/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __MESH_H__
#define __MESH_H__

#include "../../../Utils/DynamicArray.h"
#include "../../../Utils/DynamicArray2D.h"
#include "../Object3D.h"
#include "../Curves/AbstractCurve.h"
#include "../../Output/Serializable.h"

class Mesh: public Object3D, Serializable {
public:
	enum SELECTION_TYPE {
		NO_SELECTION = 0,
		TEMP_SELECTION,
		PERS_SELECTION
	};

protected:
	struct MeshPoint {
		Point4D mPoint;
		SELECTION_TYPE mSelected;
	};
	cInt mU;
	cInt mV;
	cBool mIsPeriodic;
	cBool mMeshVisible;
	cBool mControlPointsVisible;
	cBool mControlPointsCoordinatesVisibility;
	cWinColor mMeshColor;
	cWinColor mSurfaceColor;
	DynamicArray2D<MeshPoint> mMesh;

	virtual cVoid Create(AbstractCurve* curve1, AbstractCurve* curve2);
	cVoid RenderControlPoints(Renderer& renderer, Matrix4D& matrix, 
		ProjectionPlane& plane, cWinColor color);
public:

    /**************************************************************
    * Constructors                                                *
    ***************************************************************/
    Mesh();
	virtual ~Mesh();        
    /**************************************************************
    * Operators                                                   *
    ***************************************************************/


    /**************************************************************
    * Other helpful functions                                     *
    ***************************************************************/
	cVoid SelectPoint(cInt iRow, cInt iCol, SELECTION_TYPE eSelected);
	SELECTION_TYPE SelectPoint(cInt iIndex, cInt iCol, cBool bSelect);
	cVoid DeselectPoints();
	cInt GetRowCount();
	cInt GetColCount();

	virtual cVoid Init(cInt iRow, cInt iCol);
	virtual Point4D GetMeshPoint(cInt iRow, cInt iCol);
	virtual cVoid UpdateMeshPoint(cInt iRow, cInt iCol, Point4D point);
	virtual cVoid SetMeshPoint(cInt iRow, cInt iCol, Point4D point);

	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);
	virtual cVoid Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color);
	cVoid DisplayInfo(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane);

	virtual cVoid SwitchControlPointsVisibility();
	virtual cVoid SwitchControlPointsCoordinatesVisibility();
	virtual cVoid SwitchMeshVisibility();
	virtual cVoid ChangeU(cInt iU);
	virtual cVoid ChangeV(cInt iV);
	cBool ArePointsCoordinatesVisible();
	virtual cVoid SwitchPeriodic();
	virtual cVoid SetPeriodic(cBool bPeriodic);

	virtual TiXmlElement* Serialize(TiXmlElement* parent);
};                                                                 

#endif // __MESH_H__